﻿using FlashGameSite.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FlashGameSite
{
    public partial class FormMyWall : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.Cookies.AllKeys.Contains("fguid"))
            {
                Response.Redirect("Login.aspx?prev=MyWall.aspx");
            }

            if (!IsPostBack)
            {
                GetMemberActivites();
            }
        }

        private void GetMemberActivites()
        {
            using (FlashGamesDataContext dataContext = new FlashGamesDataContext())
            {
                GridActivities.DataSource = dataContext.GetWallActivity();
                GridActivities.DataBind();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtMessageText.Text))
            {
                if (txtMessageText.Text.Length > 10)
                {
                    string[] splitStr = Request.Cookies["fguid"].Value.Split('/');
                    long userId = Convert.ToInt64(splitStr[0]);
                    string username = splitStr[1];

                    using (FlashGamesDataContext dataContext = new FlashGamesDataContext())
                    {
                        Common.AddMemberActivity(username, userId, txtMessageText.Text, ActivityType.Custom);
                    }

                    txtMessageText.Text = "";
                    GetMemberActivites();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(pnlActivities, this.GetType(), "alert", "alert('Write more than 10 characters')", true);
                }
            }
        }
    }
}